<template>
	<div class="card-page">
		<tool-bar nav="" :title="action_name + 'Api枚举'">
			<el-button size="small" @click="$router.push('/dev/data-enum/add')" v-if="$props.action=='edit'">新建</el-button>
			<el-button size="small" @click="save_click" type="primary">保存</el-button>
		</tool-bar>
		<div class="card">
            <kv label="name">
                <el-input v-model="info.name" chk="*" />
            </kv>
            <kv label="remark">
                <el-input v-model="info.remark" type="textarea"/>
            </kv>
        </div>
		<div>
			<ref-table-key-value-string title="枚举定义" v-model="info.items">
			</ref-table-key-value-string>

		</div>
	</div>
</template>

<script setup>
/**
 * Created by CodeGenerator  at 2023-10-19 08:12:29
 */

import RefTableKeyValueString from "./ref-table-key-value-string.vue"




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"info":{"items":[]}});
const info = $computed(()=> $data.info );

const $props = defineProps({
    action: { type: String } ,
    id : { type: String }
});




const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);

const action = $computed( function() {
    return $props.id ? "edit" : "add";
});
const action_name = $computed( function() {
    return {add: "添加", edit: "修改"}[$props.action]
});

const loadData = async function() {
    if (!$props.id) return;
    let res = await jv.$http.post("/dev/data-enum/detail/" + $props.id)
    $data.info = res.data.data;
};
const save_click = async function() {
//校验
    if (jv.chk_main() == false) {
        return;
    }
    let res = await jv.$http.post("/dev/data-enum/save", $data.info)
//[axios拦截器中已处理了异常]。
    jv.info(action_name + " 成功");
    let id = res.data.data || $data.info.id;
    if (!id) {
        return jv.error("找不到 id");
    }
};

onMounted( function() {
    loadData();
} )



</script>

<style scoped lang="scss">
</style>
